package GUI;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Font;
import java.io.IOException;
import java.util.Vector;

import javax.swing.JButton;
import javax.swing.JOptionPane;

import Messages.MessageDeleteBusinessMenu;

import Messages.MessageGetRecipesToRightListForUpdStandMenu;
import Messages.MessageGetRecipesToRightListForUpdStandMenuReply;
import Messages.MessageShowBusinessMenusReply;

import Messages.MessageShowBusinessMenus;

/**
 * Class for creation right side panel for control of selected standard menu
 * @author Andrey,Igor
 *
 */
public class PanelFunctionStandardMenuThis  extends PanelFunctionsEmpty{

	private static final long serialVersionUID = 1L;
	private MainMenu mainMenu;
	
	private Vector<String> standardMenu;
	private String IDSupp;
	
	private JButton button_editMenu;
	private JButton button_DeleteMenu;
	private JButton button_new_menu;
	private JButton button_dohotEmployee;
	private JButton button_view_menu;
	private String flag="standart";
	
	
public PanelFunctionStandardMenuThis(MainMenu mm,Vector <String> menu)
{
	super();
	this.standardMenu=menu;
	this.mainMenu=mm;
	this.add(get_button_BuildNewMenu());
	this.add(get_button_editMenu());
	this.add(get_button_DeleteMenu(standardMenu));
	//this.add(get_button_ViewMenu());
}
	
/**
 * Method for creation JButton button_new_menu that opens window for creation new standard  menu(PfAddNewStandardMenu)
 * @return button_new_menu
 */	
private JButton get_button_BuildNewMenu() 
{
	if (button_new_menu == null) 
	{			
		button_new_menu=new JButton("בניית תפריט רגיל ");  			 
		button_new_menu.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 15));
		button_new_menu.setPreferredSize(new Dimension(220, 30));
		
		button_new_menu.addActionListener(new java.awt.event.ActionListener() 
		   {
			public void actionPerformed(java.awt.event.ActionEvent e) 
			{
				System.out.println("tables actionPerformed()"); 
				mainMenu.getContentPane().remove(((BorderLayout)mainMenu.getContentPane().getLayout()).getLayoutComponent(BorderLayout.CENTER));
				mainMenu.getContentPane().add(new PfAddNewBusinessMenu(mainMenu), BorderLayout.CENTER);	
				mainMenu.getContentPane().validate();					
			}
		});
	}
	return button_new_menu;
}





	
/**
 * Method for creation JButton 	button_editMenu that opens window for updating selected standard menu(PfUpdateStandardMenu)
 * @return button_editMenu
 */	
private JButton get_button_editMenu() 
	{
		if (button_editMenu == null) 
		{			
			button_editMenu=new JButton(" עדכון תפריט");  			 
			button_editMenu.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 15));
			button_editMenu.setPreferredSize(new Dimension(220, 30));
			button_editMenu.addActionListener(new java.awt.event.ActionListener() 
			   {
				public void actionPerformed(java.awt.event.ActionEvent e) 
				{
					mainMenu.getContentPane().remove(((BorderLayout)mainMenu.getContentPane().getLayout()).getLayoutComponent(BorderLayout.CENTER));
					mainMenu.getContentPane().add(new PfUpdateStandardMenu(mainMenu,standardMenu), BorderLayout.CENTER);					
					mainMenu.getContentPane().validate();						
				}
			});
		}
		return button_editMenu;
	}
	
	
	
/**
 * Method for creation JButton 	button_DeleteMenu that deletes selected standard menu
 * @param main 
 * @return button_DeleteMenu
 */	
private JButton get_button_DeleteMenu(final Vector<String> main) 
	{
		if (button_DeleteMenu == null) 
		{			
			button_DeleteMenu=new JButton("מחיקת תפריט");  			 
			button_DeleteMenu.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 15));
			button_DeleteMenu.setPreferredSize(new Dimension(220, 30));
			
			button_DeleteMenu.addActionListener(new java.awt.event.ActionListener() 
			   {
				public void actionPerformed(java.awt.event.ActionEvent e) 
				{
						
					int n = JOptionPane.showConfirmDialog(
						    null,
						    "    אתה בטוח?",
						    "    בקשת אישור  ",
						    JOptionPane.YES_NO_OPTION);
					 
					 if(n!=1){
                     MessageDeleteBusinessMenu msgDelMenu=new MessageDeleteBusinessMenu (standardMenu.get(0));
                     
						try {
							mainMenu.ms.client.sendToServer(msgDelMenu);
							mainMenu.getContentPane().remove(((BorderLayout)mainMenu.getContentPane().getLayout()).getLayoutComponent(BorderLayout.CENTER));
							MessageShowBusinessMenus msgShowMenu=new MessageShowBusinessMenus( );
							mainMenu.ms.client.sendToServer(msgShowMenu);
							MessageShowBusinessMenusReply resultMenu=(MessageShowBusinessMenusReply)mainMenu.ms.client.GetMessage();
							mainMenu.getContentPane().add(new PfSearch_business_menu(mainMenu,resultMenu.getResultMenu()), BorderLayout.CENTER);	
							mainMenu.getContentPane().validate();
						}
						
						catch (IOException e1) {
							// TODO Auto-generated catch block
							e1.printStackTrace();
												
						}
	  			
				}
					 }
			});
		}
		return button_DeleteMenu;
	}

/**
 * Method for creation JButton button_view_menu that opens window with all dishes of selected standard menu(PfShow_all_recipes_in_this_standard_menu)
 * @return button_view_menu
 */
/*private JButton get_button_ViewMenu() 
{
	if (button_view_menu == null) 
	{			
		button_view_menu=new JButton("לראות תפריט");  			 
		button_view_menu.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 15));
		button_view_menu.setPreferredSize(new Dimension(220, 30));
		
		button_view_menu.addActionListener(new java.awt.event.ActionListener() 
		   {
			public void actionPerformed(java.awt.event.ActionEvent e) 
			{
				MessageGetRecipesToRightListForUpdStandMenu msgDelMenu=new MessageGetRecipesToRightListForUpdStandMenu (standardMenu.get(0),flag);

			 	

				try {
					mainMenu.ms.client.sendToServer(msgDelMenu);
					MessageGetRecipesToRightListForUpdStandMenuReply resultMenu=(MessageGetRecipesToRightListForUpdStandMenuReply)mainMenu.ms.client.GetMessage();
					
					//mainMenu.getContentPane().remove(((BorderLayout)mainMenu.getContentPane().getLayout()).getLayoutComponent(BorderLayout.EAST));
					mainMenu.getContentPane().remove(((BorderLayout)mainMenu.getContentPane().getLayout()).getLayoutComponent(BorderLayout.CENTER));
					mainMenu.getContentPane().add(new PfShow_all_recipes_in_this_standard_menu(mainMenu,resultMenu.getResultRecipes()), BorderLayout.CENTER);	
				//	mainMenu.getContentPane().add(new PanelFunctionMenuListAllBusMenu(mainMenu), BorderLayout.EAST);
					mainMenu.getContentPane().validate();
				}
				
				catch (IOException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
										
				}					
			}
		});
	}
	return button_view_menu;
}*/
}

